package com.example.downloadpictures;import java.util.ArrayList;import java.util.List;import java.util.Timer;import java.util.TimerTask;import java.util.concurrent.Executors;import java.util.concurrent.ScheduledExecutorService;import java.util.concurrent.TimeUnit;import android.app.Activity;import android.content.pm.ActivityInfo;import android.graphics.Bitmap;import android.os.AsyncTask;import android.os.Bundle;import android.os.Handler;import android.support.v4.view.PagerAdapter;import android.support.v4.view.ViewPager;import android.support.v4.view.ViewPager.OnPageChangeListener;import android.util.Log;import android.view.KeyEvent;import android.view.View;import android.view.View.OnClickListener;import android.view.ViewGroup;import android.webkit.WebSettings;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.Button;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.TextView;import android.widget.Toast;import com.example.downloadpictures.object.WebServiceItem;import com.example.downloadpictures.utils.Utils;public class MainActivity extends Activity {private final String HOST_ADDRESS = "http://122.114.20.230:8888";private final String RESOURCE_ADDRESS = "/DiaoLan/android/ad/list.jsp";private final String SERVER_ADDRESS = HOST_ADDRESS RESOURCE_ADDRESS;private boolean loopPlayState = false;private List<WebServiceItem> mData = null;private List<ImageView> mImageViewList = null;private List<View> mViewList = null;private TextView mArticleTitle = null;private ViewPager mViewPager = null;private MyPagerAdapter adapter = null;private WebView mWebView;// webView调用private LinearLayout mCustomSpace = null;private Handler mHandler = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);this.initWidget();}private void initWidget() {// TODO Auto-generated method stubmViewPager = (ViewPager) this.findViewById(R.id.viewpager);mArticleTitle = (TextView) this.findViewById(R.id.article_title);mCustomSpace = (LinearLayout) this.findViewById(R.id.custom_space);mHandler = new Handler();mData = new ArrayList<WebServiceItem>();mImageViewList = new ArrayList<ImageView>();mViewList = new ArrayList<View>();adapter = new MyPagerAdapter();loadData();mViewPager.setAdapter(adapter);// 设置一个监听器,当ViewPager中的页面改变时调用mViewPager.setOnPageChangeListener(new MyPageChangeListener());}private void loadData() {// TODO Auto-generated method stubnew DownLoad(null).execute(SERVER_ADDRESS);}private final class ClickListener implements OnClickListener {private int mPosition;public ClickListener() {// TODO Auto-generated constructor stub}public ClickListener(int mPosition) {this.mPosition = mPosition;}@Overridepublic void onClick(View v) {if (v instanceof ImageView) {String url = mData.get(mPosition).getmArticleUrl();Toast.makeText(MainActivity.this, url, 1).show();} else {return;}}}private final class MyPagerAdapter extends PagerAdapter {@Overridepublic int getCount() {// TODO Auto-generated method stubreturn mImageViewList.size();}@Overridepublic void destroyItem(ViewGroup container, int position, Object object) {// TODO Auto-generated method stub((ViewPager) container).removeView(mImageViewList.get(position));}@Overridepublic Object instantiateItem(ViewGroup container, int position) {// TODO Auto-generated method stubImageView temp = mImageViewList.get(position);new DownLoad(temp).execute(mData.get(position).getmPictureUrl());((ViewPager) container).addView(temp);return temp;}@Overridepublic boolean isViewFromObject(View arg0, Object arg1) {// TODO Auto-generated method stubreturn arg0 == arg1;}}private final class DownLoad extends AsyncTask<String, Void, Bitmap> {private ImageView mImageView;public DownLoad(ImageView imageView) {mImageView = imageView;}@Overrideprotected Bitmap doInBackground(String... params) {// TODO Auto-generated method stubtry {if (params[0].equals(SERVER_ADDRESS)) {String json = (String) (Utils.getData(params[0],String.class));mData = Utils.fromJson(json);mImageViewList.clear();Log.e("图片地址", mData.get(0).getmPictureUrl());Log.e("还原", Utils.toJson(mData));} else {Bitmap bitmap = (Bitmap) (Utils.getData(params[0],Bitmap.class));return bitmap;}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}return null;}@Overrideprotected void onPostExecute(Bitmap result) {// TODO Auto-generated method stubsuper.onPostExecute(result);if (result != null) {mImageView.setImageBitmap(result);if (!loopPlayState) {mArticleTitle.setText(mData.get(0).getmTitle());mViewPager.setCurrentItem(0);mHandler.postDelayed(loopPlay, 3000);loopPlayState = true;}} else {for (int i = 0; i < mData.size(); i ) {Log.e("JRSEN-MDATA", mData.size() "");ImageView imageView = new ImageView(MainActivity.this);imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));imageView.setOnClickListener(new ClickListener(i));mImageViewList.add(imageView);View view = new View(MainActivity.this);LayoutParams layoutParams = new LayoutParams(14, 14);layoutParams.setMargins(3, 0, 3, 0);view.setLayoutParams(layoutParams);view.setBackgroundResource(R.drawable.dot_normal);mCustomSpace.addView(view);mViewList.add(view);}adapter.notifyDataSetChanged();}}}/** * 当ViewPager中页面的状态发生改变时调用 * * @author Administrator * */private class MyPageChangeListener implements OnPageChangeListener {private int historyPosition = 0;/** * 当ViewPager中页面的状态发生改变时调用 */public void onPageSelected(int position) {mArticleTitle.setText(mData.get(position).getmTitle());mViewList.get(historyPosition).setBackgroundResource(R.drawable.dot_normal);mViewList.get(position).setBackgroundResource(R.drawable.dot_focused);historyPosition = position;}public void onPageScrollStateChanged(int arg0) {}public void onPageScrolled(int arg0, float arg1, int arg2) {}}Runnable loopPlay = new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubint position = mViewPager.getCurrentItem();if (position == (mData.size() - 1)) {position = 0;mViewPager.setCurrentItem(position);} else {mViewPager.setCurrentItem( position);}P.error("position thread" position "mData" mData.size());mHandler.postDelayed(loopPlay, 3000);}};/** * 该类为测试类 * * @author Jrsen * */private final static class P {public static void error(Object str) {Log.e("JRSEN", (String) str);}}}
下载android 加载网络轮播图片 示例源码用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论